package com.weishi.project.sport.movement.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.project.sport.movement.service.MovementService;
import com.weishi.project.training.domain.Dynamometer;
import com.weishi.project.training.domain.DynamometerSubsection;
import com.weishi.project.training.domain.HeartRate;
import com.weishi.project.training.service.IDynamometerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

@Api(value = "运动员端--运动模块", description = "运动员端--运动模块")
@RestController
@CrossOrigin("*")//解决移动端跨域
@RequestMapping("/sportMovement/")
public class MovementController extends BaseController {

    /**
     * 运动模块接口
     */
    @Autowired
    private MovementService movementService;

    /**
     * 测功仪数据接口
     */
    @Autowired
    private IDynamometerService dynamometerService;


    private Logger logger = Logger.getLogger("MovementController");


    @ApiOperation("运动员端--根据当前时间--查询我的运动计划列表--根据开始时间排序")
    @RequestMapping(value = "getSportsPlan", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getSportsPlan(String day) {
        return movementService.getSportsPlan(day, currentLoginSportsman().getId());
    }


    @ApiOperation("运动员端--查询运动计划详情")
    @RequestMapping(value = "getSportsPlanDetails", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getSportsPlanDetails(String id) {
        return movementService.getSportsPlanDetails(currentLoginSportsman().getId(), id);
    }


    @ApiOperation("运动员端--查询运动--乳酸")
    @RequestMapping(value = "getLacticAcid", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getLacticAcid(String firstLevel, Integer trainingMode , Integer groupId , Integer trainingDayId) {
        return movementService.getLacticAcid(currentLoginSportsman().getId(), firstLevel, trainingMode , groupId , trainingDayId);
    }


    @ApiOperation("运动员端--查询运动--专项成绩信息")
    @RequestMapping(value = "getWaterInformation", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getWaterInformation(Integer id, Integer trainingMode, String firstLevel , Integer groupId) {
        return movementService.getWaterInformation(currentLoginSportsman().getId(), id, trainingMode, firstLevel , groupId);
    }


    @ApiOperation("运动员端--查询运动--专项成绩信息--成绩对标")
    @RequestMapping(value = "getWaterAlignment", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getWaterAlignment(Integer id, Integer trainingMode, String firstLevel , Integer groupId) {
        return movementService.getWaterAlignment(currentLoginSportsman().getId(), id, trainingMode, firstLevel , groupId);
    }


    @ApiOperation("运动员端--查询运动--专项成绩信息--船速及桨频")
    @RequestMapping(value = "getWaterShipPulp", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getWaterShipPulp(Integer id, Integer trainingMode, String firstLevel , Integer groupId) {
        return movementService.getWaterShipPulp(currentLoginSportsman().getId(), id, trainingMode, firstLevel , groupId);
    }


    @ApiOperation("运动员端--运动模块--新增心率")
    @RequestMapping(value = "addHeartRate", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult addHeartRate(@RequestBody Map<String, List<HeartRate>> stringListMap) {
        logger.info("addHeartRate ：*********"+ stringListMap.toString()+"*********");
        List<HeartRate> list = stringListMap.get("content");
        for(HeartRate heartRate : list){
            movementService.addHeartRate(currentLoginSportsman().getId().intValue(), heartRate);
        }
        return AjaxResult.success();
    }


    @ApiOperation("运动员端--运动模块--查询测功仪数据")
    @RequestMapping(value = "getDynamometerList", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getDynamometerList(Integer groupId , Integer trainingDayId) {
        return movementService.getDynamometerList(currentLoginSportsman().getId() , groupId , trainingDayId);
    }


    @ApiOperation("运动员端--新增测功仪数据")
    @ResponseBody
    @RequestMapping(value = "addDynamometer", method = RequestMethod.POST)
    public AjaxResult addDynamometer(@RequestBody JSONObject trainingReportBean) {
        return movementService.addDynamometer(trainingReportBean, currentLoginSportsman().getId());
    }


    @ApiOperation("运动员端--根据训练日 id 用户 userId 查询数据")
    @RequestMapping(value = "getTrainingDayById", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getTrainingDayById(Integer id) {
        return movementService.getTrainingDayById(id, currentLoginSportsman().getId());
    }


    @ApiOperation("运动员端--根据主键删除测功仪数据")
    @RequestMapping(value = "deleteDynamometerById", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult deleteDynamometerById(Integer id) {
        return movementService.deleteDynamometerById(id);
    }


    @ApiOperation("运动员端--根据主键 修改 测功仪数据")
    @RequestMapping(value = "updateDynamometerById", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateDynamometerById(Dynamometer dynamometer) {
        return movementService.updateDynamometerById(dynamometer);
    }


    @ApiOperation("运动员端--测功仪--查询心率")
    @RequestMapping(value = "getDynamometerHeartRate", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getDynamometerHeartRate(Integer trainingDayId , Integer trainingMode , Integer groupId) {
        return movementService.getDynamometerHeartRate(currentLoginSportsman().getId() , trainingDayId , trainingMode , groupId);
    }


    @ApiOperation("运动员端--心率表--查询心率")
    @RequestMapping(value = "getHeartRateList", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getHeartRateList(Integer trainingDayId , Integer groupId) {
        return movementService.getHeartRateList(currentLoginSportsman().getId() , trainingDayId , groupId);
    }


    @ApiOperation("运动员端--计算平均心率，最大心率")
    @RequestMapping(value = "getAverageAndMax", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getAverageAndMax(Integer trainingDayId , Integer trainingMode , Integer groupId , String firstLevel) {
        return movementService.getAverageAndMax(currentLoginSportsman().getId() , trainingDayId , trainingMode , groupId , firstLevel);
    }


    @ApiOperation("运动员 -- 今日专项成绩排名")
    @RequestMapping(value = "getThisDayRanking", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getThisDayRanking(Integer groupId , String boatType , Integer trainingDayId , Integer trainingMode , Integer kilometers , Double realClassHour , String firstLevel)
    {
        return movementService.getThisDayRanking(groupId , boatType , trainingDayId , currentLoginSportsman().getSex() , trainingMode , kilometers , realClassHour , firstLevel);
    }


    @ApiOperation("运动员 -- 测功仪存储分段成绩")
    @RequestMapping(value = "addDynamometerSubsection", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult addDynamometerSubsection(@RequestBody DynamometerSubsection dynamometerSubsection)
    {
        return movementService.addDynamometerSubsection(currentLoginSportsman().getId() , dynamometerSubsection);
    }


    @ApiOperation("运动员 -- 运动员点击清空数据，根据时间查询重复数据，并且删除重复数据")
    @RequestMapping(value = "getRepetitionList", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getRepetitionList(Integer groupId)
    {
        dynamometerService.remove(Wrappers.<Dynamometer>lambdaQuery()
                .eq(Dynamometer::getGroupId , groupId)
                .eq(Dynamometer::getSportsmanId , currentLoginSportsman().getId()));
        return AjaxResult.success();
    }


    @ApiOperation("运动员 -- 测功仪点击开始训练查询，是否已经训练 true:代表可以训练，false:代表不能训练")
    @RequestMapping(value = "getDynamometerRankingOne", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getDynamometerRankingOne(@RequestBody JSONObject jsonObject)
    {
        return movementService.getDynamometerRankingOne(currentLoginSportsman().getId() , jsonObject);
    }




}
